package com.xnfh.network.api

import com.xnfh.common.bean.BaiDuCoddingBean
import com.xnfh.common.bean.CropBean
import com.xnfh.common.bean.EquipmentGl
import com.xnfh.common.bean.EquipmentToken
import com.xnfh.common.bean.EquipmentTokenV1
import com.xnfh.common.bean.FieldDetailBean
import com.xnfh.common.bean.FieldJfJy
import com.xnfh.common.bean.FieldListBean
import com.xnfh.common.bean.FieldWeatherBean
import com.xnfh.common.bean.FindFieldRecordS
import com.xnfh.common.bean.GateWayBean
import com.xnfh.common.bean.GateWayTotalInfoBean
import com.xnfh.common.bean.GuanGaiBean
import com.xnfh.common.bean.HomeStatisticsNum
import com.xnfh.common.bean.KcBean
import com.xnfh.common.bean.NzGlBean
import com.xnfh.common.bean.PlantOptionBean
import com.xnfh.common.bean.SoilZdMessage
import com.xnfh.common.bean.UserInforBean
import com.xnfh.common.bean.WarningBean
import com.xnfh.common.bean.WeatherDetailBean
import com.xnfh.common.bean.WeatherMessage
import com.xnfh.common.bean.WeatherWarningBean
import com.xnfh.framework.bean.BaseResp
import com.xnfh.framework.bean.UserInfo
import com.xnfh.network.constant.BASEURL
import com.xnfh.network.constant.BASE_SFJ_URL
import com.xnfh.network.constant.BASE_URL_OTHER
import com.xnfh.network.constant.BASE_URL_OTHER1
import okhttp3.MultipartBody
import okhttp3.RequestBody
import retrofit2.http.Body
import retrofit2.http.FieldMap
import retrofit2.http.FormUrlEncoded
import retrofit2.http.GET
import retrofit2.http.Headers
import retrofit2.http.Multipart
import retrofit2.http.POST
import retrofit2.http.Part
import retrofit2.http.Query

/**
 * @Description:
 * @author ziheng
 * @date 2023/1/12 16:35
 */
interface ApiService {
    @GET("/user/information")
    suspend fun getUserInfoById(): BaseResp<UserInfo>

    @POST("/buried/data")
    suspend fun getPoint(@Body requestBody: RequestBody): BaseResp<Any>

    /**
     * 登录
     */
    @Headers("$BASEURL: $BASE_URL_OTHER")
    @POST("api/sysuser/login")
    suspend fun reqeustLogin(@Body requestBody: RequestBody): BaseResp<String>

    /**
     * 获取用户权限
     */
    @GET("api/sysuser/getOperator")
    suspend fun requestUserInfor(): BaseResp<UserInforBean>

    /**
     * 获取首页天气预警消息
     */
    @POST("api/field/getLonlatDamage")
    suspend fun requestWaetherWarning(@Body requestBody: RequestBody): BaseResp<List<WeatherWarningBean>>

    /**
     * 获取首页天气
     */
    @Headers("$BASEURL: $BASE_URL_OTHER1")
    @GET("v1/grid/gridNowHourMeteo")
    suspend fun requestWeather(@Query("lonlats") lonlats: String): BaseResp<WeatherDetailBean>

    @GET("api/field/fieldStatisticsUser")
    suspend fun requestFieldStatistics(): BaseResp<HomeStatisticsNum>

    /**
     * 获取百度逆编码
     */
    @GET("http://api.map.baidu.com/reverse_geocoding/v3")
    suspend fun requestGeoCodding(
        @Query("location") location: String,
        @Query("ak") ak: String = "epKHKl5qCj3TPp8VBZILTE2ATLxgabLQ",
        @Query("coordtype") coordtype: String = "wgs84ll",
        @Query("extensions_town") extensions_town: String = "true",
        @Query("mcode") mcode: String = "Mobile_Android",
        @Query("output") output: String = "json"
    ): BaseResp<BaiDuCoddingBean>

    /**
     * 作物列表
     */
    @POST("api/sysCrop/getList")
    suspend fun requestCropList(@Body requestBody: RequestBody): BaseResp<List<CropBean>>

    /**
     * 圈地之后-添加的地块信息
     */
    @Multipart
    @POST("api/field/add")
    suspend fun requestAddField(@Part parts: List<MultipartBody.Part>): BaseResp<Any>

    /**
     * 获取田块列表
     */
    @POST("api/field/pageList")
    suspend fun requestFiels(@Body requestBody: RequestBody): BaseResp<FieldListBean>

    /**
     * 获取田块详情
     */
    @POST("api/framarea/homeApi/geFieldDetail")
    suspend fun requestFiledDetail(@Body requestBody: RequestBody): BaseResp<FieldDetailBean>

    /**
     * 通过地块的经纬度获取天气相关
     */
    @Headers("$BASEURL: $BASE_URL_OTHER1")
    @GET("v1/grid/gridNowHourMeteo")
    suspend fun requestFieldWeather(@Query("lonlats") lonlats: String): BaseResp<FieldWeatherBean>

    /**
     * 田块详情的积温、积雨
     */
    @Headers("$BASEURL: $BASE_URL_OTHER1")
    @GET("v1/meteo/tempandrainday")
    suspend fun requestFiledJwJy(@Query("lonlat") lonlat: String): BaseResp<FieldJfJy>

    /**
     * 获取土壤诊断信息
     */
    @GET("api/field/soilField")
    suspend fun requestSoilZdMessage(
        @Query("fieldId")fieldId: String,
        @Query("lonlats")lonlats: String
    ): BaseResp<SoilZdMessage>

    /**
     * 删除地块
     */
    @POST("api/field/del")
    suspend fun requestRemoveField(@Body requestBody: RequestBody): BaseResp<Any>

    /**
     * 编辑地块
     */
    @POST("api/field/fieldUpdate")
    suspend fun requestEditField(@Body requestBody: RequestBody): BaseResp<Any>

    /**
     * 轮作地块
     */
    @POST("api/field/fieldRotation")
    suspend fun requestLzField(@Body requestBody: RequestBody): BaseResp<Any>

    /**
     * 种植方案列表
     */
    @POST("api/scheme/getSchemeListApp")
    suspend fun requestSchemeList(@Body requestBody: RequestBody): BaseResp<List<PlantOptionBean>>

    /**
     * 获取巡田记录列表
     */
    @POST("api/farming/getPageList")
    suspend fun requestFindFieldRecords(@Body requestBody: RequestBody): BaseResp<FindFieldRecordS>

    /**
     * 删除巡田记录
     */
    @POST("api/farming/del")
    suspend fun requestDelFindFieldRecord(@Body requestBody: RequestBody): BaseResp<Any>

    /**
     * 添加巡田记录
     */
    @Multipart
    @POST("api/farming/add")
    suspend fun requestAddXunTian(@Part parts: List<MultipartBody.Part>): BaseResp<Any>

    /**
     * 获取水肥机设备的token
     */
    @GET("api/auth/getApiToken")
    suspend fun requestApiToken(): BaseResp<EquipmentToken>

    /**
     * 获取水肥机设备的tokenV1
     */
    @GET("api/auth/getToken")
    suspend fun requestApiTokenV1(): BaseResp<EquipmentTokenV1>

    /**
     * 获取气象设备id
     */
    @POST("api/sysFarmGateway/getGatewayByFarmAppList")
    suspend fun requestGetewayList(@Body requestBody: RequestBody): BaseResp<List<GateWayBean>>

    /**
     * 获取水肥机的预警日志
     */
    @Headers("$BASEURL: $BASE_SFJ_URL")
    @POST("/gateway/api/v2/Log/GetSystemLogListByPage")
    suspend fun requestWarningList(@Body requestBody: RequestBody): BaseResp<WarningBean>


    /**
     * 获取KC设别列表
     */
    @POST("api/sysFarmGateway/getGatewayByFarmAppPage")
    suspend fun requestKcList(@Body requestBody: RequestBody): BaseResp<KcBean>

    /**
     * 获取kc 网关详情
     */
    @Headers("$BASEURL: $BASE_SFJ_URL")
    @GET("/gateway/api/v2/Gateway/GetGatewayDetai2Info")
    suspend fun requestKcDetail(@Query("gatewayid")gatewayid: String): BaseResp<GateWayTotalInfoBean>

    /**
     * 获取灌溉日志
     */
    @Headers("$BASEURL: $BASE_SFJ_URL")
    @POST("/gateway/api/v2/Log/GetFlowLogListByPage")
    suspend fun requestGuangaiList(@Body requestBody: RequestBody): BaseResp<GuanGaiBean>

    /**
     * 获取气象设备
     */
    @POST("api/ws_gateway/listWeatherStation")
    suspend fun requestWeatherList(@Body requestBody: RequestBody): BaseResp<EquipmentGl>

    /**
     * 11.17 气象指标瞬时值（app端）
     */
    @GET("api/ws_gateway/wsInstantValue")
    suspend fun requestWeatherMessage(@Query("gatewayId")gatewayId: String): BaseResp<WeatherMessage>

    /**
     * 农资管理
     */
    @POST("api/bus/agriType/agriStatByType")
    suspend fun requestNzList(@Body requestBody: RequestBody): BaseResp<NzGlBean>

    /**
     * 开关阀门v1
     */
    @Headers("$BASEURL: $BASE_SFJ_URL")
    @POST("/kc/v1/hwapi/Device/SyncOpenCloseDevice")
    suspend fun requestDevice(@Body requestBody: RequestBody): BaseResp<Any>

    /**
     * v2
     * 搅拌开关
     * DeviceIndex是3-6用的阀门
     */
    @Headers("$BASEURL: $BASE_SFJ_URL")
    @POST("/gateway/api/v2/Device/DeviceValveStir")
    suspend fun requestDeviceV2Jiaob(@Body requestBody: RequestBody):BaseResp<Any>

    /**
     * V2
     * 阀门开关（灌溉泵/施肥泵/阀门）
     * DeviceIndex其他的阀门
     */
    @Headers("$BASEURL: $BASE_SFJ_URL")
    @POST("/gateway/api/v2/Device/DeviceValveManual")
    suspend fun requestDeviceV2Fm(@Body requestBody: RequestBody):BaseResp<Any>

}